/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.generic;

import canteen.sys.SessionFactoryClass;
import canteen.sys.model.entity.repository.AuthorDAO;
import canteen.sys.model.entity.repository.AuthorDAOImpl;
import canteen.sys.model.entity.repository.ItemDAO;
import canteen.sys.model.entity.repository.ItemDAOImpl;
import canteen.sys.model.entity.repository.LanguageDAO;
import canteen.sys.model.entity.repository.LanguageDAOImpl;
import canteen.sys.model.entity.repository.OwnerDAO;
import canteen.sys.model.entity.repository.OwnerDAOImpl;
import canteen.sys.model.entity.repository.OwnerItemDAO;
import canteen.sys.model.entity.repository.OwnerItemDAOImpl;
import canteen.sys.model.entity.repository.StatusOfUseDAO;
import canteen.sys.model.entity.repository.StatusOfUseDAOImpl;
import canteen.sys.model.entity.repository.StoreDAO;
import canteen.sys.model.entity.repository.StoreDAOImpl;
import canteen.sys.model.entity.repository.TypeOfRegulationDAO;
import canteen.sys.model.entity.repository.TypeOfRegulationDAOImpl;
import canteen.sys.model.entity.repository.TypeOfUseDAO;
import canteen.sys.model.entity.repository.TypeOfUseDAOImpl;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author TNT
 */
public class HibernateDAOFactory extends DAOFactory {

    private HibernateDAOFactory() {
    }

    public static HibernateDAOFactory getInstance() {
        return HibernateDAOFactoryHolder.INSTANCE;
    }

    public Session getCurrentSession() {
        return SessionFactoryClass.getInstance().getSessionFactory().getCurrentSession();
    }

    private GenericHibernateDAOSupport instantiateDAO(Class daoClass) {
        try {
            GenericHibernateDAOSupport dao = (GenericHibernateDAOSupport) daoClass.newInstance();
            dao.setSession(getCurrentSession());
            return dao;
        } catch (InstantiationException | IllegalAccessException | HibernateException ex) {
            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
        }
    }

    @Override
    public TypeOfUseDAO getTypeOfUseDAO() {
        return (TypeOfUseDAO) instantiateDAO(TypeOfUseDAOImpl.class);
    }

    @Override
    public AuthorDAO getAuthorDAO() {
        return (AuthorDAO) instantiateDAO(AuthorDAOImpl.class);
    }

    @Override
    public ItemDAO getItemDAO() {
        return (ItemDAO) instantiateDAO(ItemDAOImpl.class);
    }

    @Override
    public LanguageDAO getLanguageDAO() {
        return (LanguageDAO) instantiateDAO(LanguageDAOImpl.class);
    }

    @Override
    public OwnerDAO getOwnerDAO() {
        return (OwnerDAO) instantiateDAO(OwnerDAOImpl.class);
    }
    
    @Override
    public OwnerItemDAO getOwnerItemDAO() {
        return (OwnerItemDAO) instantiateDAO(OwnerItemDAOImpl.class);
    }

    @Override
    public StatusOfUseDAO getStatusOfUserDAO() {
        return (StatusOfUseDAO) instantiateDAO(StatusOfUseDAOImpl.class);
    }

    @Override
    public StoreDAO getStoreDAO() {
        return (StoreDAO) instantiateDAO(StoreDAOImpl.class);
    }

    @Override
    public TypeOfRegulationDAO getTypeOfRegulationDAO() {
        return (TypeOfRegulationDAO) instantiateDAO(TypeOfRegulationDAOImpl.class);
    }

//    @Override
//    public BillDetailDAO getBillDetailDAO() {
//        return (BillDetailDAO) instantiateDAO(BillDetailDAOImpl.class);
//    }
//
//    @Override
//    public BillMasterDAO getBillMasterDAO() {
//        return (BillMasterDAO) instantiateDAO(BillMasterDAOImpl.class);
//    }
    private static class HibernateDAOFactoryHolder {

        private static final HibernateDAOFactory INSTANCE = new HibernateDAOFactory();
    }
}
